public class Test {
    public int func(String s){
        int count = 0;
        boolean flag = false;
        for(int i = 0;i < s.length();i++){
            if(s.charAt(i)==' '){
                flag = false;
            }
            if(!flag && !(s.charAt(i) == ' ')){
                flag = true;
                count++;
            }
        }
        return count;
    }

    public static void main(String[] args) {
        Test test = new Test();
        int i = test.func("Hello, my name is John");
        System.out.println(i);

    }

}
